package com.jiaozi.system.controller;


import com.jiaozi.core.annotation.Log;
import com.jiaozi.core.table.JzTable;
import com.jiaozi.base.utils.bean.R;
import com.jiaozi.system.pojo.param.sys.department.DepartmentSaveUpdateParam;
import com.jiaozi.system.pojo.param.sys.department.DepartmentTreeParam;
import com.jiaozi.system.pojo.vo.sys.department.DepartmentInfoVO;
import com.jiaozi.system.pojo.vo.sys.department.DepartmentTreeVO;
import com.jiaozi.system.service.SysDepartmentService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 系统-部门(SysDepartment)表控制层
 *
 * @author jiaozi
 * @since 2024-08-15 14:02:36
 */
@Tag(name = "部门管理")
@RestController
@RequestMapping("/sysDepartment")
public class SysDepartmentController {
    /**
     * 服务对象
     */
    @Autowired
    private SysDepartmentService sysDepartmentService;
    @Operation(summary = "部门初始化",description = "部门初始化")
    @GetMapping("/info")
    @ApiOperationSupport(order = 1)
    @Log("部门初始化")
    public  R<JzTable> info(){
        return R.ok(new JzTable());
    }
    @Operation(summary = "查询部门树",description = "查询部门树【本部以及子部门】")
    @GetMapping("/departmentTree")
    @ApiOperationSupport(order = 1)
    public R<List<DepartmentTreeVO>> departmentTree(DepartmentTreeParam departmentTreeParam){
        return sysDepartmentService.departmentListVOR(departmentTreeParam);
    }


    @Operation(summary = "获取部门信息",description = "获取部门信息")
    @GetMapping("/{departmentId}")
    @ApiOperationSupport(order = 3)
    public R<DepartmentInfoVO> departmentInfo(@Parameter(name ="departmentId" ,description = "部门编号", required = true)
                                              @PathVariable(value = "departmentId") String departmentId){
        return sysDepartmentService.departmentInfo(departmentId);

    }


    @Operation(summary = "新增部门信息",description = "新增部门信息")
    @PostMapping("/")
    @ApiOperationSupport(order = 2)
    public R departmentSave(@RequestBody DepartmentSaveUpdateParam departmentSaveUpdateParam){
        return sysDepartmentService.departmentSave(departmentSaveUpdateParam);
    }


    @Operation(summary = "修改部门信息",description = "修改部门信息")
    @PutMapping("/{departmentId}")
    @ApiOperationSupport(order = 3)
    public R departmentUpdate(@Parameter(name ="departmentId" ,description = "部门编号", required = true)
                              @PathVariable(value = "departmentId") String departmentId,@RequestBody DepartmentSaveUpdateParam departmentSaveUpdateParam){
        return sysDepartmentService.departmentUpdate(departmentId,departmentSaveUpdateParam);
    }





    @Operation(summary = "变更部门状态",description = "变更部门状态")
    @PutMapping("updatyeDepartmentState/{departmentId}")
    @ApiOperationSupport(order = 4)
    public R updatyeDepartmentState(@Parameter(name ="departmentId" ,description = "部门编号", required = true)
                              @PathVariable(value = "departmentId") String departmentId){
        return sysDepartmentService.updatyeDepartmentState(departmentId);
    }





}

